import {request} from '@/utils/request'
import type {LoginForm, LoginResponse, UserInfo} from '@/types/user'

/**
 * 用户登录
 * @param data 登录表单数据
 */
export function login(data: LoginForm): Promise<LoginResponse> {
  return request.post('/big-auth/login', data)
}

/**
 * 获取当前用户信息
 */
export function getUserInfo(): Promise<UserInfo> {
  return request.get('/big-auth/info')
}

/**
 * 用户退出登录
 */
export async function logout(): Promise<void> {
  await request.post('/big-auth/logout')
}

/**
 * 修改密码
 * @param oldPassword 原密码
 * @param newPassword 新密码
 */
export async function updatePassword(oldPassword: string, newPassword: string): Promise<void> {
  await request.put('/big-auth/password', null, {
    params: {
      oldPassword,
      newPassword
    }
  })
}

/**
 * 重置密码
 * @param userId 用户ID
 */
export async function resetPassword(userId: string): Promise<void> {
  await request.put(`/big-auth/password/${userId}`)
}